angular.module('starter.services', [])

.factory('Chats', function() {
  var chats = [{
    id: 0,
    content: "练背！练背！It's Showtime!Good morning Sunshine!☀#晨练让我精神百倍# #背部塑型完毕# #我要上精选# @Keep  @Keep_精选",
    url: 'http://static1.keepcdn.com/picture/2017/02/19/07/167568fedd34a3d42e00c485cb8ab11d95f0667f_1670x1670.jpg?imageMogr2/thumbnail/306x/quality/95'
  }, {
    id: 1,
    content: "继续我的减脂塑形之路～💪🏻 #每日健身打卡# #无深蹲不翘臀# #胸肌腹肌统统都要# #我要上精选#",
    url: 'http://static1.keepcdn.com/picture/2017/02/18/21/b9a8cc43fb859b717b86db19bb6d31e6c1133c36_1458x2000.jpg?imageMogr2/thumbnail/306x/quality/95'

  }, {
    id: 2,
    content: "健身改变了我的生活，你呢？不管你做不做，而我，已经开始了。#将自律 keep 到底# #我要上精选#",
    url: 'http://static1.keepcdn.com/picture/2017/02/18/21/408161b01bf82fcaae311be4228a0e1464a96cd1_2000x2000.jpg?imageMogr2/thumbnail/306x/quality/95'
  },{
    id: 3,
    content: "加油～ #我要上精选#",
    url: 'http://static1.keepcdn.com/picture/2017/02/18/20/213561fe943412696996d76b3d359b68870b7ab9_1500x2000.jpg?imageMogr2/thumbnail/306x/quality/95'
  }];

  return {
    // 返回chats数组
    all: function() {
      return chats;
    },
    // remove方法用于删除一个联系人
    remove: function(chat) {
      // splice()方法用于插入、删除或者替换数组元素
      // 参数1：待删除数组元素的下标
      // 参数2：删除元素的个数
      chats.splice(chats.indexOf(chat), 1);
    },
    // get方法得到联系人
    // for循环遍历chats数组
    get: function(chatId) {
      for (var i = 0; i < chats.length; i++) {
        if (chats[i].id === parseInt(chatId)) {
          return chats[i];
        }
      }
      return null;
    }
  };
});
